package com.baizhi.service.impl;

import com.baizhi.dao.UserDAO;
import com.baizhi.entity.User;
import com.baizhi.entity.UserQuery;
import com.baizhi.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDAO userDAO;
    @Override
    public PageInfo<User> selectAll(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<User> list = userDAO.selectAll();
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public User selectByPrimaryKey(Integer userId) {
        User user = userDAO.selectByPrimaryKey(userId);
        return user;
    }

    @Override
    public void updateStatus(User user) {
        if(user.getUserStatus()==0){
            user.setUserStatus(1);
        }else {
            user.setUserStatus(0);
        }
        userDAO.updateStatus(user);
    }

    @Override
    public List<User> selectCount(){
        List<User> users = userDAO.selectCount();
        return users;
    }

    @Override
    public List<UserQuery> selectQuery() {
        List<UserQuery> userQueries = userDAO.selectQuery();
        return userQueries;
    }

    @Override
    public User selectCountDate(Integer count) {
        User user = userDAO.selectCountDate(count);

        return user;
    }

    @Override
    public List<Map> selectCountDate1() {
        List<Map> maps = userDAO.selectCountDate1();
        System.out.println("maps="+maps);
        return maps;
    }
}
